#ifndef _SEARCH_TREE_H_
#define _SEARCH_TREE_H_

class CSearchTree
{
public:
	typedef struct
	{
		void* value;
		int flags;
	}TInfo;
private:
	static const int SYMBOL_COUNT = 40;
	static const int STACK_DEPTH = 64;
	typedef struct _item
	{
		TInfo info;
		_item* next[SYMBOL_COUNT];
		_item* parent;
		char parent_sym;
	}TItem;

	TItem *m_root;
	TItem *m_searchItem;
	int m_stack[STACK_DEPTH];
	int m_stackPos;

private:
	TItem* CreateItem(TItem *parent, char sym);
	void DeleteItem(TItem *item);
	inline int GetSymbolPos(char c);
	inline char GetSymbolChar(int pos);
	TItem* FindItem(char *key, bool create);
	void GetName(TItem *item, char *name);
	void FindValidItem(TItem *item);
public:
	CSearchTree();
	~CSearchTree();

	void Add(char *key, void* value, int flags=0);
	TInfo* Find(char *key);

	bool FindFirst(char *key, char* name);
	bool FindNext(char* name);
};
#endif //_SEARCH_TREE_H_